***cleaning AJD1  ***** 
****

clear 
set more off 

set scheme lean2
*set scheme swift_red
graph set window fontface "Arial Narrow"

global tt1 cells(b(star fmt(%-9.3f)) se(fmt(%-9.3f) par( [ ] )) blank) stats (r2 N, fmt(%9.2f %9.0g)) style(fixed) starlevel("*" 0.10 "**" 0.05 "***" 0.01)

use "$Data\26302-0001-Data.dta"
do "$Data\26302-0001-Supplemental_syntax.do"

cd "$Base"

**** cleaning **** 

gen gender =  0
replace gender = 1 if AQ75 == 2
gen age = 0
replace age = 1 if AQ78_BRAC == 5
replace age = 2 if AQ78_BRAC == 4
replace age = 3 if AQ78_BRAC == 3
replace age = 4 if AQ78_BRAC == 2
replace age = 5 if AQ78_BRAC == 1

gen debt_at_graduation = AQ72A_BRAC
gen white = 0
replace white = 1 if ARACE_IMP == 5
gen pid = .
replace pid =1 if AQ43 == 1
replace pid = 2 if AQ43 ==2
replace pid = 3 if AQ43 == 3
replace pid = 2 if AQ43 == 4

gen income_bracket = AQ88_BRAC

gen ideo_social = AQ44A 
gen ideo_econ = AQ44B

gen married = 0
replace married = 1 if inrange(AQ85, 2,4)
replace married = . if AQ85 == .

gen any_children = 0 
replace any_children = 1 if AQ87A !=0
gen n_children = AQ87A

gen consider_politics = .
replace consider_politics = 1 if AQ64_F == 1
replace consider_politics = 0 if AQ64_F == 2

foreach var of varlist AQ45_1-AQ45_17 {
	gen `var'b = 0
	replace `var'b = 1 if `var' == 3 | `var'==4
	recode `var' 2=1 1=0
	replace `var'b = . if `var'==.
}
egen participation_all = rowtotal (AQ45_1-AQ45_17)

egen lead_all = rowtotal (AQ45_1b-AQ45_1b)

gen participation_gender = AQ45_11
gen lead_gender = AQ45_11b
gen participation_polparty = AQ45_1
gen lead_polparty = AQ45_1b
gen participation_poladvoc = AQ45_2
gen lead_poladvoc = AQ45_2b
gen participation_pta = AQ45_3
gen lead_pta = AQ45_3b
gen participation_civic = AQ45_13
gen lead_civic = AQ45_13b


egen agentic_workplace = rowmean(AQ40_A AQ40_F AQ40_F)
egen communal_workplace = rowmean(AQ40_C AQ40_D AQ40_E)

egen agentic_lawschool = rowmean(AQ65_A AQ65_C AQ65_E AQ65_G)
egen communal_lawschool = rowmean(AQ65_B AQ65_F)

egen agentic_career = rowmean(AQ38_A AQ38_H AQ38_I)
egen communal_career = rowmean(AQ38_F AQ38_G)

egen agentic_satisfaction = rowmean(AQ26_A AQ26_B AQ26_E)
egen communal_satisfaction = rowmean(AQ26_H AQ26_J AQ26_N AQ26_P)

foreach var of varlist agentic_workplace communal_workplace agentic_lawschool communal_lawschool agentic_career communal_career agentic_satisfaction communal_satisfaction {
	sum `var'
	gen `var'_scale = (`var' -`r(min)') / (`r(max)'-`r(min)')
}


foreach var of varlist AQ29_A AQ29_B AQ29_C AQ29_D {
	recode `var' 2=0
}
egen discrim_all = rowmean(AQ29_A AQ29_B AQ29_C AQ29_D)
rename AQ29_A discrim_comment
rename AQ29_B discrim_assign
rename AQ29_C discrim_client
rename AQ29_D discrim_other

gen communal_employment = 0
gen govt_employment = 0
foreach var of varlist APOS1ORG APOS2ORG APOS3ORG APOS4ORG {
	replace communal_employment = 1 if `var' == 4
	replace communal_employment = 1 if `var' == 6
	replace govt_employment = 1 if `var' == 2
	replace govt_employment = 1 if `var' == 3
}

gen law_rank = AUSNEWS03

gen per_work_male= AQ19 

gen pro_bono_work = AQ11D_1 
	sum pro_bono_work
	gen pro_bono_work_scale = (pro_bono_work -`r(min)') / (`r(max)'-`r(min)')

*** labeling variables *** 

label var gender "Gender"
label define gender 0 "women" 1 "men"

label var pid "Party ID"
label define pid 1 "Democrat" 2 "Independent" 3 "Republican"
label var ideo_social "Social policy ideology"
label var ideo_econ "Economic policy ideology"

label var any_children "Any minor children"
label var n_children "Number of minor children"

label var married "Married or partnered"

label var age "Age"
label define age 1 "Under 28" 2 "28-29" 3 "29-30" 4 "33-38" 5 "39+"

label var law_rank "Law school ranking"
label var consider_politics "Considered politics as alternative to law"

label var communal_employment "Works or worked in non-profit or public interest law"
label var govt_employment "Works or worked in govt"

label var per_work_male "% of workplace who are men"
label var pro_bono_work "Pro-bono hours at work"

label var agentic_workplace_scale "Agentic reasons for picking workplace"
label var communal_workplace_scale "Communal reasons for picking workplace"
label var agentic_satisfaction_scale "Agentic satisfaction w work"
label var communal_satisfaction_scale "Communal satisfaction w work"
label var agentic_lawschool_scale "Agentic reasons for choosing law school"
label var communal_lawschool_scale "Communal reasons for choosing law school"
label var agentic_career_scale "Agentic reasons for career sector"
label var communal_career_scale "Communal reasons for career sector"


*** saving 

save "$Data\ajd1_cleaned.dta", replace 


keep ASU_ID pro_bono_work_scale law_rank per_work_male govt_employment communal_employment discrim_all communal_satisfaction_scale agentic_satisfaction_scale communal_career_scale agentic_career_scale communal_lawschool_scale agentic_lawschool_scale communal_workplace_scale agentic_workplace_scale communal_satisfaction agentic_satisfaction communal_career agentic_career communal_lawschool agentic_lawschool communal_workplace agentic_workplace lead_civic participation_civic lead_pta participation_pta lead_poladvoc participation_poladvoc lead_polparty participation_polparty lead_gender participation_gender lead_all participation_all married n_children income_bracket pid white discrim_assign discrim_client discrim_comment discrim_other debt_at_graduation gender ideo_econ ideo_social consider_politics any_children age

foreach var of varlist pro_bono_work_scale law_rank per_work_male govt_employment communal_employment discrim_all communal_satisfaction_scale agentic_satisfaction_scale communal_career_scale agentic_career_scale communal_lawschool_scale agentic_lawschool_scale communal_workplace_scale agentic_workplace_scale communal_satisfaction agentic_satisfaction communal_career agentic_career communal_lawschool agentic_lawschool communal_workplace agentic_workplace lead_civic participation_civic lead_pta participation_pta lead_poladvoc participation_poladvoc lead_polparty participation_polparty lead_gender participation_gender lead_all participation_all married n_children income_bracket pid white discrim_assign discrim_client discrim_comment discrim_other debt_at_graduation gender ideo_econ ideo_social consider_politics any_children age {
	rename `var' `var'w1
}

gen wave = 1
gen year = 2002

save "$Data\adj1_reduced.dta", replace 
